def colorful_warning(w):
    from colorama import Fore, Style
    print(Fore.RED + w)
    print(Style.RESET_ALL)
    return w

def data_inpute(a):
    if a == 0:
        data.append(input("请输入{}".format(data_xuan[a])))
    elif a == 1:
        data.append(eval(input("请输入{}".format(data_xuan[1]))))
    elif a == 2:
        data.append(eval(input("请输入{}".format(data_xuan[2]))))
    elif a == 3:
        data.append(eval(input("请输入{}".format(data_xuan[3]))))

def check (c,a):
    global data
    if c == "sex":
        if a in sex_man:
            data[0] = "男"
            print("当前正在输入男性数据")
        elif a in sex_woman:
            data[0] = "女"
            print("当前正在输入女性数据")
        else:
            data[0] = input("请输入正确的{}！".format(data_xuan[0]))
            check("sex",data[0])
    elif c == "kg":
        while a < 2 or a > 750:
            kg_ask = ""
            kg_ask = input(colorful_warning("确定输入的体重为{}kg吗？（输入回车确定，输入任意字符重新输入）".format(a)))
            while kg_ask == "":
                return a
            else:
                data[1] = eval(input("请重新输入{}：".format(data_xuan[1])))
                check("kg", data[1])
                break
    elif c == "cm":              #检查用户是否输入正常范围的身高
        while a < 40 or a > 250:
            cm_ask = ""
            cm_ask = input(colorful_warning("确定输入的身高为{}cm吗？（输入回车确定，输入任意字符重新输入）".format(a)))
            while cm_ask == "":
                return a
            else:
                data[2] = eval(input("请重新输入{}：".format(data_xuan[2])))
                check("cm", data[2])
                break
    elif c == "age":        #检查用户是否输入正常范围的年龄
        while a < 0 or a > 200:
            age_ask = ""
            age_ask = input(colorful_warning("确定输入的年龄为{}岁吗？（输入回车确定，输入任意字符重新输入）".format(a)))
            while age_ask == "":
                return a
            else:
                data[3] = eval(input("请重新输入{}：".format(data_xuan[3])))
                check("age", data[3])
                break

def data_inpute_worse(a):   #主函数
    global data
    while True:
        try:
            data_inpute(a)                  #接收数据的输入
            check(data_unit[a],data[a])     #检查输入的数据
        except:
            continue
        break

def c_bmr(sex,kg,cm,age):   #计算bmr的函数
    if sex in sex_man:
        bmr = 10*kg+6.25*cm-5*age+5
    else:
        bmr = 10*kg+6.25*cm-5*age-161
    return bmr

ask = "y"
data = []
data_xuan = ["性别","体重数据（KG）","身高数据（cm）","年龄数据(岁）"]
data_unit = ["sex","kg","cm","age"]
sex_man = ("男")
sex_woman = ("女")
print("{0:*^30}".format("欢迎使用BMR(基础代谢率)计算器"))
while True:

    b_e = input("是否退出程序（y/n）：")
    if b_e == 'y':
        print("{0:*^30}".format("退出计算器"))
        break
    elif b_e == 'n':

        while ask == "y" or "Y" or "yes" or "Yes":
            for i in range (4) :
                data_inpute_worse(i)
            # print("您的bmr指数为{}".format(c_bmr(data[0],data[1],data[2],data[3])))
            print("你的BMR计算报告\n"
                  "性别：{}\n"
                  "年龄：{}岁\n"
                  "身高：{}cm\n"
                  "体重：{}kg\n"
                  "BMR指数：{:.2f}\n".format(data[0], data[1], data[2], data[3],c_bmr(data[0], data[1], data[2], data[3])))
            data = []  # 清空列表，准备进入下次循环
            end = input("是否退出程序（y/n）")
            if end == 'y':
                print("{0:*^30}".format("退出计算器，感谢你的使用( •̀ ω •́ )✧"))
                break
        break
    else:
        colorful_warning("继续程序请输入n，退出程序请输入y，请重新输入！")


